<template>
  <div class="content-block">
    <div class="info-head">{{ title }}</div>
    <div class="info-content">
      <v-chart
        :option="options"
        style="width: 100%; height: 400px"
        :theme="chartTheme" autoresize
      ></v-chart>
    </div>
  </div>
</template>

<script>
import MixinChartOptionToolbox from '@/mixins/chart-option-toolbox';
import { defaultNumber } from '@/utils';
import MixinVchartTheme from '@/mixins/mixin-vchart-theme';

export default {
  name: 'industry-chart',
  mixins: [MixinChartOptionToolbox, MixinVchartTheme],
  props: {
    title: String,
    data: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  data () {
    return {
      dataViewFirstCellName: '行业'
    }
  },
  computed: {
    options() {
      return {
        tooltip: {
          show: true,
          trigger: 'axis'
        },
        legend: {
          show: true
        },
        grid: {
          containLabel: true,
          top: '70px',
          left: '60px',
          right: '60px',
        },
        toolbox: this.chartOptionToolbox,
        xAxis: [
          {
            type: 'category',
            data: this.data.xaxis ? this.data.xaxis.data : []
          }
        ],
        yAxis: {
          type: 'value',
          axisLine: {
            show: true
          }
        },
        series: [
          ...(this.data.series || []).map((v, i) => ({
            name: v.name,
            type: 'bar',
            stack: 'total',
            // emphasis: {
            //   focus: 'series'
            // },
            data: v.data,
            tooltip: {
              valueFormatter: value => `${defaultNumber(value)} ${v.unit}`
            }
          }))
        ]
      };
    }
  }
};
</script>

<style lang="scss" scoped>
@import '../../assets/style/variable.scss';

.content-block {
  background: white;
  border-radius: 4px;

  .info-head {
    padding: 20px $gutter 0 $gutter;
    font-size: 16px;
  }

  .info-content {
    padding-top: 40px;
  }
}
</style>
